﻿using LY.Entity;
using LY.Entity.PageSearch;
using LY.Entity.SearchEntity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LY.DataAccess.Repository
{
    public class BankCardRepository : BaseRepository
    {
        //绑定银行卡
        public long BindBankCard(U_BankCard bangCard)
        {
            return base.Insert(bangCard);
        }
        //获取银行卡信息
        public PagedList<U_BankCard> GetBankCardList(int id, PageView view)
        {
            string cols = @"[Id]
                          ,[MemberId]
                          ,[CardNO]
                          ,[CardName]
                          ,[BankName]
                          ,[AddTime] ";
            string sqlWhere = " and MemberId="+id;
            //if (!string.IsNullOrEmpty(search.AddedTime))
            //{
            //    sqlWhere += "AND convert(varchar,[AddedTime],120) like '%" + search.AddedTime + "%'";
            //}
            //return base.PageGet<U_BankCard>(view, cols, @" [U_BankCard]", sqlWhere, " [Sequence]", "");
            return base.PageGet<U_BankCard>(view, cols, @" [U_BankCard] ", sqlWhere, "[Id] ASC", "");
        }
        //删除绑定
        public int DeleteCard(int id)
        {
            string sql = "delete from U_BankCard where Id=@ID";
            return base.Excute(sql, new { ID = id });
        }

        //根据会员id查询银行卡信息
        public List<U_BankCard> GetbankcardList(int mID)
        {
            string sql = "SELECT [Id],[MemberId],[CardNO],[CardName],[BankName],[AddTime] FROM [U_BankCard] where MemberId=@MemberId";
            return base.Query<U_BankCard>(sql, new { MemberId =mID});
        }
        //根据银行卡号获取绑定信息
        public U_BankCard Getcard(string card)
        {
            string sql = "SELECT [Id],[MemberId],[CardNO],[CardName],[BankName],[AddTime] FROM [U_BankCard] where CardNO=@CardNO";
            return base.Get<U_BankCard>(sql, new { CardNO = card });
        }
        //根据银ID获取绑定信息
        public U_BankCard GetcardByID(int id)
        {
            string sql = "SELECT [Id],[MemberId],[CardNO],[CardName],[BankName],[AddTime] FROM [U_BankCard] where Id=@Id";
            return base.Get<U_BankCard>(sql, new { Id = id });
        }

         //根据项目id获取银行卡信息
        public U_BankCard GetCardByProId(int projectId)
        {
            string sql = "SELECT [Id],[MemberId],[ProjectId],[CardNO],[CardName],[BankName],[AddTime] FROM [U_BankCard] where ProjectId=@ProjectId";
            return base.Get<U_BankCard>(sql, new { ProjectId = projectId });
        }

    } 
}
